import React from 'react';
import { Tabs } from 'antd';
import router from 'umi/router';
import _ from 'lodash';
import * as apis from '@/services/SupplyPlanMgr';

export default function CurrentStage(props) {
  let activeKey = '';
  const { orgStructure, match } = props;
  const { level1, level2, project, stage } = match.params;
  let stages = {};
  if (!_.isEmpty(orgStructure.data)) {
    stages = _.filter(orgStructure.data, {
      parentOrgid: project,
    });
  }
  stages = _.orderBy(stages, ['orgorder'], ['asc']);

  if (props.location.pathname.search('EntireProject') === -1) {
    if (stage) {
      activeKey = stage;
    } else {
      activeKey = stages[0].orgdepid;
    }
  } else {
    activeKey = 'EntireProject';
  }

  if (!_.isEmpty(orgStructure.data) && project) {
    return (
      <div className="header-stages">
        <Tabs
          size="large"
          activeKey={activeKey}
          animated={false}
          defaultActiveKey="1"
          onChange={key => {
            if (key === 'EntireProject') {
              router.push(
                `/OperatingPlan/ReturnMoneyPlan/EntireProject/${level1}/${level2}/${project}`,
              );
            } else {
              // 根据价格管理版本当前分期最新版本信息 跳转分期最新的版本 默认跳转  CastDecision 版本
              // const params = { projectFid: key };
              router.replace(
                `/OperatingPlan/ReturnMoneyPlan/${level1}/${level2}/${project}/${key}/dynamic`,
              );
              // apis.newestVersionStageUsingGET({ params }).then(data => {
              //   if (data.data && data.data !== 'pricing') {
              //     router.replace(
              //       `/OperatingPlan/ReturnMoneyPlan/${level1}/${level2}/${project}/${key}/${data.data}`,
              //     );
              //   } else {
              //     router.replace(
              //       `/OperatingPlan/ReturnMoneyPlan/${level1}/${level2}/${project}/${key}/investment`,
              //     );
              //   }
              // });
            }
          }}
        >
          <Tabs.TabPane tab="全盘回款计划" key="EntireProject" />
          {!_.isEmpty(stages) &&
            stages.map(value => <Tabs.TabPane tab={value.orgname} key={value.orgdepid} />)}
        </Tabs>
      </div>
    );
  }
  return null;
}
